package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.Saleman;
import com.sl.au.repository.SalemanRepository;
import com.sl.au.service.SalemanService;

/**
 * 销售人员管理接口
 * @author XH
 *
 */
@Service("SalemanService")
@Transactional
public class SalemanServiceImpl extends BaseServiceImpl implements SalemanService {

	@Autowired
	SalemanRepository salemanRepository;
	
	public SalemanRepository getRepository(){
		return this.salemanRepository;
	}
	
	@Override
	public List<Saleman> getPage(int start, int length, String key, String orderName, String dir) {
		Page<Saleman> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"id");
		pages=salemanRepository.findAll(pageable);
		return pages.getContent();
	}
	
	@Override
	public List<Saleman> getSalemans(int start, int length, String key, String orderName, String dir) {
		Page<Saleman> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"id");
		pages=salemanRepository.getSalemans(key,pageable);
		return pages.getContent();
	}

}
